home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / vdi.arc / VDIGRAPH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1985-05-01  |  7.3 KB  |  290 lines

  1. /*
  2.  *  Program to do the MegaMorphic Computing and Consulting
  3.  *  corporate report chart for 1985 using VDI.
  4.  */
  5.  
  6. #define MIN(A,B) (A)<(B) ? (A) : (B)
  7.  
  8. #define BLACK 0
  9. #define WHITE 1
  10. #define RED 2
  11. #define GREEN 3
  12. #define BLUE 4
  13. #define YELLOW 5
  14. #define CYAN 6
  15. #define MAGENTA 7
  16.  
  17. int scale;
  18.  
  19. main()
  20. {
  21. int xy[100],
  22.     i,
  23.     height_req,
  24.     line_length,
  25.     char_width,
  26.     cell_width,
  27.     cell_height,
  28.     title_size,
  29.     hor_out,
  30.     workout[66],
  31.     device_handle,
  32.     vert_out;
  33.  
  34. static  int   workin[] = {1,1,RED,3,1,1,WHITE,0,0,GREEN,
  35.                           1,'D','I','S','P','L','A','Y',' '};
  36. extern  int   scale;
  37. static  int   echo_xy[] = {0, 0};
  38. static  int   arrow[] = {130, 90, 136, 80, 130, 70,
  39.                          130, 74, 126, 74, 126, 86,
  40.                          130, 86, 130, 90};
  41. char    input_string[2];
  42.  
  43.     /* initialize the device and put characteristics in workout */
  44.     v_opnwk(workin,&device_handle,workout);
  45.  
  46.     /* create scaling based on aspect ratio of the device */
  47.     scale = MIN(workout[51] / 240, workout[52] / 180);
  48.  
  49.     /* set a new character height */
  50.     title_size = 16;
  51.     vst_height(device_handle,to32k(title_size),
  52.                &char_width,&cell_width,&cell_height);
  53.  
  54.     /* find out how long ruling is in NDC */
  55.     line_length = to32k(240);
  56.  
  57.     /*
  58.      * loop making sure that the title won't be
  59.      * longer than the ruling
  60.      */
  61.     while (cell_width >= line_length  / 36 &&
  62.           title_size >= 2) {
  63.  
  64.         /* try a new height */
  65.         vst_height(device_handle,
  66.                           to32k(--title_size),&char_width,
  67.                           &cell_width,&cell_height);
  68.     }
  69.  
  70.     /* write out title */
  71.     v_gtext(device_handle,to32k(10),to32k(163),
  72.                       "MegaMorphic Computing and Consulting");
  73.  
  74.     /* compute size for other text */
  75.     height_req = (float)to32k(title_size) / 2;
  76.  
  77.     /* set character height smaller */
  78.     vst_height(device_handle,height_req,
  79.                &char_width,&cell_width,&cell_height);
  80.  
  81.     /* set connecting point to upper left corner of text */
  82.     vst_alignment(device_handle,0,2,&hor_out,&vert_out);
  83.  
  84.     /* change text color */
  85.     vst_color(device_handle,YELLOW);
  86.  
  87.     /* write out subtitle */
  88.     v_gtext(device_handle,to32k(10),to32k(156),
  89.                       "1985 Corporate Report");
  90.  
  91.     /* create data to draw ruling */
  92.     xy[0] = to32k(10); xy[1] = to32k(160);
  93.     xy[2] = to32k(240); xy[3] = to32k(160);
  94.  
  95.     /* draw the ruling */
  96.     v_pline(device_handle,2,xy);
  97.  
  98.     /* change text color */
  99.     vst_color(device_handle,RED);
  100.  
  101.     /* write out pie label */
  102.     v_gtext(device_handle,to32k(106),to32k(40),
  103.                       "Our");
  104.     v_gtext(device_handle,to32k(106),
  105.                       (int)(to32k(40)-cell_height*1.5),
  106.                       "Share");
  107.  
  108.     /* set alignment to bottom left */
  109.     vst_alignment(device_handle,0,0,&hor_out,&vert_out);
  110.  
  111.     /* change text color */
  112.     vst_color(device_handle,BLUE);
  113.  
  114.     /* write out labels for bar chart */
  115.     v_gtext(device_handle,to32k(172),to32k(40),
  116.                       "Support 46%");
  117.  
  118.     vst_color(device_handle,GREEN);
  119.     v_gtext(device_handle,to32k(172),to32k(90),
  120.                       "Consulting 27%");
  121.  
  122.     vst_color(device_handle,RED);
  123.     v_gtext(device_handle,to32k(172),to32k(120),
  124.                       "Systems 27%");
  125.  
  126.     /* set the interior style to solid */
  127.     vsf_interior(device_handle,1);
  128.  
  129.     /* create coordinates for first bar */
  130.     xy[0] = to32k(144); xy[1] = to32k(30);
  131.     xy[2] = to32k(170); xy[3] = to32k(80);
  132.  
  133.     /* change fill color */
  134.     vsf_color(device_handle,BLUE);
  135.  
  136.     /* draw bar */
  137.     v_bar(device_handle,xy);
  138.  
  139.     /* set the interior style to empty */
  140.     vsf_interior(device_handle,0);
  141.  
  142.     /* outline the bar */
  143.     v_bar(device_handle,xy);
  144.  
  145.     /* modify for second bar */
  146.     xy[1] = to32k(80); xy[3] = to32k(110);
  147.  
  148.     /* change fill color */
  149.     vsf_color(device_handle,GREEN);
  150.  
  151.     /* set interior style to hatch */
  152.     vsf_interior(device_handle,3);
  153.  
  154.     /* use narrow 45 degree lines */
  155.     vsf_style(device_handle,1);
  156.  
  157.     /* draw second bar */
  158.     v_bar(device_handle,xy);
  159.  
  160.     /* set the interior style to empty */
  161.     vsf_interior(device_handle,0);
  162.  
  163.     /* outline the bar */
  164.     v_bar(device_handle,xy);
  165.  
  166.     /* modify for third bar */
  167.     xy[1] = to32k(110); xy[3] = to32k(140);
  168.  
  169.     /* change fill color */
  170.     vsf_color(device_handle,RED);
  171.  
  172.     /* set interior style to hatch */
  173.     vsf_interior(device_handle,3);
  174.  
  175.     /* use medium 45 degree lines */
  176.     vsf_style(device_handle,2);
  177.  
  178.     /* draw third bar */
  179.     v_bar(device_handle,xy);
  180.  
  181.     /* set interior style to empty */
  182.     vsf_interior(device_handle,0);
  183.  
  184.     /* outline the bar */
  185.     v_bar(device_handle,xy);
  186.  
  187.     /* set text alignment to top center */
  188.     vst_alignment(device_handle,1,2,&hor_out,&vert_out);
  189.  
  190.     /* change text color */
  191.     vst_color(device_handle,YELLOW);
  192.  
  193.     /* write out subtitles */
  194.     v_gtext(device_handle,to32k(60),to32k(20),
  195.                       "Market Breakdown");
  196.     v_gtext(device_handle,to32k(170),to32k(20),
  197.                       "Product Breakdown");
  198.  
  199.     /* change fill color */
  200.     vsf_color(device_handle,GREEN);
  201.  
  202.     /* set fill interior to hatch */
  203.     vsf_interior(device_handle,3);
  204.  
  205.     /* draw pie slice */
  206.     v_pieslice(device_handle,to32k(60),to32k(80),
  207.                          to32k(50),450,3150);
  208.  
  209.     /* set interior style to empty */
  210.     vsf_interior(device_handle,0);
  211.  
  212.     /* draw the outline of the big pie slice */
  213.     v_pieslice(device_handle,to32k(60),to32k(80),
  214.                          to32k(50),450,3150);
  215.  
  216.     /* change fill color */
  217.     vsf_color(device_handle,RED);
  218.  
  219.     /* set the interior style to solid */
  220.     vsf_interior(device_handle,1);
  221.  
  222.     /* draw small pie slice */
  223.     v_pieslice(device_handle,to32k(70),to32k(80),
  224.                          to32k(50),3150,450);
  225.  
  226.     /* set interior style to empty */
  227.     vsf_interior(device_handle,0);
  228.  
  229.     /* outline the small pie slice */
  230.     v_pieslice(device_handle,to32k(70),to32k(80),
  231.                          to32k(50),3150,450);
  232.  
  233.     /* change fill color */
  234.     vsf_color(device_handle,YELLOW);
  235.  
  236.     /* set interior style to solid */
  237.     vsf_interior(device_handle,1);
  238.  
  239.     /* for every one of the points in the arrow array */
  240.     for (i=0;i<=15;i++)     {
  241.  
  242.       /* transform the points */
  243.       xy[i] = to32k(arrow[i]);
  244.  
  245.      }
  246.  
  247.     /* fill the arrow */
  248.     v_fillarea(device_handle,8,xy);
  249.  
  250.     /* set the interior style to empty */
  251.     vsf_interior(device_handle,0);
  252.  
  253.     /* outline the arrow */
  254.     v_fillarea(device_handle,8,xy);
  255.  
  256.     /* wait for <CR> */
  257.     vrq_string(device_handle,2,0,echo_xy,input_string);
  258.  
  259.     /* if first char is upper c do a hardcopy */
  260.     if (input_string[0] == 'C')     {
  261.  
  262.       /* call for hardcopy */
  263.       v_hardcopy(device_handle);
  264.     }
  265.  
  266.     /* clear the workstation */
  267.     v_clrwk(device_handle);
  268.  
  269.     /* leave graphics mode */
  270.     v_enter_cur(device_handle);
  271.  
  272.     /* close down the workstation */
  273.     v_clswk(device_handle);
  274.  
  275. }
  276.  
  277. int   to32k(world)
  278. int   world;
  279.  
  280. /*
  281.  *  function to take world coordinates
  282.  *  and translate them to NDC space.
  283.  */
  284.  
  285. {
  286.     extern  scale;
  287.  
  288.     return(world * scale);
  289. }
  290.